package com.yshkj.payment.service.impl;

import com.yshkj.payment.dto.CommonJsonDto;
import com.yshkj.payment.dto.SpecSaleDto;
import com.yshkj.payment.dto.SpecSaleListDto;
import com.yshkj.payment.entity.medicinal.Spec;
import com.yshkj.payment.repository.SpecRepository;
import com.yshkj.payment.service.SpecService;
import com.yshkj.payment.service.impl.operator.SpecListSaleHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by 唐旭 on 2016/10/6.
 */
@Service
public class SpecServiceImpl implements SpecService {

    @Autowired
    private SpecRepository specRepository;

    @Override
    public SpecSaleListDto findSpec(String code) {
        List<Spec> list = specRepository.findOneByCode(code);
        SpecSaleListDto result = new SpecSaleListDto(list);
        result.setState(!list.isEmpty());
        return result;
    }

    @Override
    public CommonJsonDto saleSpecList(List<SpecSaleDto> list) {
        SpecListSaleHandler handler = new SpecListSaleHandler(list);
        return handler.sale();
    }
}
